package com.trhui.mallbook.client;

import com.trhui.mallbook.config.MallBookConfig;
import com.trhui.mallbook.domain.common.ApiRequest;
import com.trhui.mallbook.domain.common.BaseResponse;
import com.trhui.mallbook.domain.request.dg.DgPaymentOrderRequest;
import com.trhui.mallbook.domain.request.hf.HfPayOrderCloseRequest;
import com.trhui.mallbook.domain.request.hf.HfPaymentOrderRequest;
import com.trhui.mallbook.domain.request.xib.XibRefreshCashierDeskRequest;
import com.trhui.mallbook.domain.request.xib.XibSplitOrderFrontRequest;
import com.trhui.mallbook.domain.request.yb.YbPaymentOrderRequest;
import com.trhui.mallbook.domain.response.dg.DgPaymentOrderResponse;
import com.trhui.mallbook.domain.response.hf.HfPayOrderCloseResponse;
import com.trhui.mallbook.domain.response.hf.HfPaymentOrderResponse;
import com.trhui.mallbook.domain.response.yb.YbPaymentOrderResponse;
import com.trhui.mallbook.enums.ChannelTypeEnum;
import com.trhui.mallbook.enums.ServerCodeEnum;

/**
 * 支付接口
 *
 * @author linqy
 */
public class PaymentClient extends AbstractClient {

    /**
     * 汇付支付接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<HfPaymentOrderResponse> hfPayment(HfPaymentOrderRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.PAYMENT_ORDER)
                .channelType(ChannelTypeEnum.HF)
                .build();
        return post(reqApiRequest, HfPaymentOrderResponse.class);
    }

    /**
     * 汇付-支付关单接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<HfPayOrderCloseResponse> hfPayOrderClose(HfPayOrderCloseRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.PAY_ORDER_CLOSE)
                .channelType(ChannelTypeEnum.HF)
                .build();
        return post(reqApiRequest, HfPayOrderCloseResponse.class);
    }

    /**
     * 易宝支付接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<YbPaymentOrderResponse> ybPayment(YbPaymentOrderRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.PAYMENT_ORDER)
                .channelType(ChannelTypeEnum.YB)
                .build();
        return post(reqApiRequest, YbPaymentOrderResponse.class);
    }

    /**
     * 厦门国际银行 前台支付接口
     *
     * @param request
     * @return
     */
    public static ApiRequest xibFrontPayment(XibSplitOrderFrontRequest request) {
        MallBookConfig config = MallBookConfig.getConfig(request.getMerchantNo());
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.SPLIT_ORDER_FRONT)
                .channelType(ChannelTypeEnum.XIB)
                .date(String.valueOf(System.currentTimeMillis()))
                .version(config.getVersion())
                .build(config.getMerchantPrivateKey());
        return reqApiRequest;
    }

    /**
     * 厦门国际银行 刷新收银台接口
     *
     * @param request
     * @return
     */
    public static ApiRequest xibRefreshCashierDesk(XibRefreshCashierDeskRequest request) {
        MallBookConfig config = MallBookConfig.getConfig(request.getMerchantNo());
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.REFRESH_CASHIER_DESK)
                .channelType(ChannelTypeEnum.XIB)
                .date(String.valueOf(System.currentTimeMillis()))
                .version(config.getVersion())
                .build(config.getMerchantPrivateKey());
        return reqApiRequest;
    }


    /**
     * 斗拱支付接口
     *
     * @param request
     * @return
     */
    public static BaseResponse<DgPaymentOrderResponse> dgPayment(DgPaymentOrderRequest request) {
        ApiRequest reqApiRequest = new ApiRequest.ApiRequestBuild()
                .merOrderId(request.getMerOrderId())
                .merchantNo(request.getMerchantNo())
                .params(request)
                .serverCode(ServerCodeEnum.PAYMENT_ORDER)
                .channelType(ChannelTypeEnum.DG)
                .build();
        return post(reqApiRequest, DgPaymentOrderResponse.class);
    }

}
